package asg.pp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class GameActivities extends Activity {
	private EditText userId;
	private Button loginButton;
	private Button quitButton;
	private PurblePlaceService service;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        service = PurblePlaceService.getInstance();
        connect();
    }
    
    private void connect() {
    	setContentView(R.layout.connect);
    	service.connect(
		PurblePlaceService.DEFAULIP, PurblePlaceService.DEFAULTPORT);
    	login();
    }
    
    protected void login() {
    	setContentView(R.layout.login);
    	userId = (EditText) findViewById(R.id.userID);
		loginButton = (Button) findViewById(R.id.loginButton);
		quitButton = (Button) findViewById(R.id.exitButton);
		
		loginButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String username = userId.getText().toString().trim();
				if(username != "")
					service.login(GameActivities.this, username);
			}
		});
		
		quitButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.i("exiting", "exiting..");
				service.exitGame();
			}
		});
    }
    
    protected void loadMainInterface() {
    	startActivity(new Intent(this, MainActivity.class));
    }
}
//public void startMainActivity() {
//	startActivity(new Intent(this, MainActivity.class));
//}